#include "StdAfx.h"
#include "PanelManager.h"
#include "assert.h"

CPanelManager::CPanelManager(CWnd* parentWnd)
{
	_parent = parentWnd;
	_curPanel = -1;
}

CPanelManager::~CPanelManager(void)
{
}

void CPanelManager::addPanel(CDialog* panel, UINT id)
{
	ASSERT(_panels.size() == _ids.size());
	this->_panels.push_back(panel);
	this->_ids.push_back(id);
}

void CPanelManager::SetRect()
{
	ASSERT(FALSE);
	CRect tabRect, itemRect;
	int nX, nY, nXc, nYc;

	_parent->GetClientRect(&tabRect);
	nX = nY = 0;
	nXc = tabRect.Width();
	nYc = tabRect.Height();
	//_parent->GetItemRect(0, &itemRect);

	//_panels[0]->GetClientRect(&itemRect);

	//nX=itemRect.left;
	//nY=itemRect.bottom+1;
	//nXc=tabRect.right-itemRect.left-2;
	//nYc=tabRect.bottom-nY-2;

	if(_panels.size() > 0)
	{
		_panels[0]->SetWindowPos(&CWnd::wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
		for( unsigned int nCount=1; nCount < _panels.size(); nCount++ )
			_panels[nCount]->SetWindowPos(&CWnd::wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
	}

}


void CPanelManager::showPanel(int index)
{
	assert(index >= 0 && index < (int)_panels.size());
	size_t nPanel = _panels.size();
	for(size_t i = 0; i < nPanel; ++i)
	{
		_panels[i]->EnableWindow(FALSE);
		_panels[i]->ShowWindow(SW_HIDE);
	}
	_panels[index]->EnableWindow(TRUE);
	_panels[index]->ShowWindow(SW_SHOW);
	_panels[index]->SetFocus();
	_curPanel = index;
};

void CPanelManager::init()
{
	//SetRect();
	CRect winrect;
	_parent->GetWindowRect(&winrect);
	INT win_width = winrect.Width();
	INT win_height = winrect.Height();


	int nPanel = (int)_panels.size();
	for( int i = 0; i < nPanel; ++i)
		_panels[i]->Create(_ids[i], _parent);

};

int CPanelManager::getPanelIndex()const
{
	return _curPanel;
}

CDialog* CPanelManager::getActivePanel()const
{
	assert((int)_panels.size() > _curPanel);
	return _panels[_curPanel];
}
